﻿
//获取事务记录
function GetRecords(empId, affairsType, tempStr) {
    var url = "../Extend/AjaxData/jsonlist.aspx?entity=hrEmployeeAffairs&condition=EmployeeID='" + empId + "' and AffairsType=" + affairsType;
    $.get(url, function (d, s) {
        var list = eval("(" + d + ")");
        if (list.total > 0) {
            for (var o in list.rows) {
                var EffectiveDate = list.rows[o].EffectiveDate;
                var Description = list.rows[o].Description;
                var Remark = list.rows[o].Remark;
                $("#Reason").text(tempStr + "原因：");
                $("#EffectiveDate").val(EffectiveDate);
                $("#Description").val(Description);
                $("#Remark").val(Remark);
                break;
            }
        }
        $("#EffectiveDate").attr("readonly", "readonly");
        $("#EffectiveDate").removeClass("Wdate");
        $("#EffectiveDate").attr("onclick", "");
        $("#Description").attr("readonly", "readonly");
        $("#Remark").attr("readonly", "readonly");
    });
}

var TempStr = "";
//初始化
if (typeof ($) != "undefined") {
    $(document).ready(function () {
        var empId = getPar1('empId');
        var affairsType = getPar(location.href, "affairsType");
        //1.在职转不在职，2.不在职转在职,3.离职,4.离退休,5.返聘,6.转正）   
        switch (affairsType) {
            case '1':
                TempStr = "在职转不在职";
                break;
            case '2':
                TempStr = "不在职转在职";
                break;
            case '3':
                TempStr = "离职";
                break;
            case '4':
                TempStr = "离退休";
                break;
            case '6':
                TempStr = "返聘";
                break;
            case '8':
                TempStr = "转正";
                break;
        }
        var flag = getPar(location.href, "flag"); //标识
        if (flag == "1") { //查看事务记录
            parent.$("#yui-gen0-button").hide();
            GetRecords(empId, affairsType, TempStr);
        }
        else {  //新增         
            $("#Reason").text(TempStr + "原因：");
            if (affairsType == 3) { //离职
                $("#dispatureTypeDiv").show();
                $("#dispatureTitle").show();
                instance[0].AffairsType = $("#dispatureType").val(); //事务类型
                $("#dispatureType").change(function () { //选择离职类型
                    instance[0].AffairsType = $("#dispatureType").val();
                });
            }
            else {
                $("#dispatureTypeDiv").hide();
                $("#dispatureTitle").hide();
                instance[0].AffairsType = affairsType; //事务类型
            }
            instance[0].flag = "0";
            instance[0].EmployeeID = empId; //人员ID
            var myDate = new Date();
            instance[0].ReportDate = myDate.getFullYear() + "-" + (myDate.getMonth() + 1) + "-" + myDate.getDate(); //提报日期
        }
        var href = decodeURI(location.href);
        $("#EmployeeCode").text(getPar(href, "empCode"));
        $("#EmployeeName").text(getPar(href, "empName"));
    });
}

//数据验证
var fnCheckData = function () {
    var effectiveDate = $("#EffectiveDate").val();
    if (effectiveDate == "") {
        return "生效日期不能为空！";
    }
    if ($("#Description").val() == "") {
        return TempStr + "原因不能为空！";
    }
}